package com.yy.studyspringboot.concurrent;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Semaphore;

public class CountDownLatchTest {
    /**  CountDownLatch---同步器
        用来多线程等待，都执行完了，再接着往下走
     */

    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(10);

        for (int i = 0; i < 10; i++) {
            int finalI = i;
            new Thread(() -> {
                System.out.println("sort :" + finalI);
                countDownLatch.countDown();
            }).start();
        }
        //等上面10个资源都执行力，这里才会放开阻塞
        countDownLatch.await();
        System.out.println("end...");
    }


}
